package com.dts.service.impl;

import com.dts.entity.Emp;
import com.dts.mapper.EmpMapper;
import com.dts.service.EmpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("empService")
@Transactional //事务注解
public class EmpServiceImpl implements EmpService {
 
    @Autowired
    private EmpMapper empMapper;
 
    @Override
    public List<Emp> getAllEmp() {
        List<Emp> emps = empMapper.getAllEmp();
        return emps;
    }
    @Override
    public PageInfo<Emp> pageQuery(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Emp> emps = empMapper.getAllEmp();
        return new PageInfo<>(emps);
    }

    @Override
    public void addEmp() {
        Emp emp = new Emp();
        emp.setEmpName("小红");
        emp.setAge(18);
        empMapper.addEmp(emp);
//        int i =1/0;
        emp.setEmpName("小红33");
        emp.setAge(20);
        empMapper.addEmp(emp);
    }

}